﻿Imports System.Data.SqlClient

Public Class clsEmpresasUsuarios
    Private mintIdUsuario As Integer
    Private mintIdEmpresa As Integer
    Public Property IdUsuario() As Integer
        Get
            Return mintIdUsuario
        End Get
        Set(ByVal value As Integer)
            mintIdUsuario = value
        End Set
    End Property
    Public Property IdEmpresa() As Integer
        Get
            Return mintIdEmpresa
        End Get
        Set(ByVal value As Integer)
            mintIdEmpresa = value
        End Set
    End Property
    Public Sub New()
        mintIdEmpresa = 0
        mintIdUsuario = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into EmpresasUsuarios (" & _
                            "IdUsuario," & _
                            "IdEmpresa) " & _
                            "VALUES (" & _
                            "@IdUsuario," & _
                            "@IdEmpresa) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = InitialConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdUsuario", mintIdUsuario)
        Command.Parameters.AddWithValue("IdEmpresa", mintIdEmpresa)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el permiso", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
